import request from "@/utils/request";
import type { 
  SupplyChainDashboardData,
  OverviewMetrics,
  InventoryAnalysis,
  TurnoverAnalysis,
  TargetAchievement,
  StorePerformance,
  InventoryAlert,
  TrendData,
  DateRangeQuery,
  StorePerformanceQuery,
  InventoryAlertQuery,
  TrendQuery
} from '@/types/supply-chain'

const SUPPLY_CHAIN_BASE_URL = "/api/v1/supply-chain/dashboard";

export const supplyChainApi = {
  /**
   * 获取供应链看板完整数据
   */
  getDashboardData(params?: DateRangeQuery) {
    return request<any, SupplyChainDashboardData>({
      url: `${SUPPLY_CHAIN_BASE_URL}/all`,
      method: "get",
      params,
    });
  },

  /**
   * 获取概览指标
   */
  getOverviewMetrics(params?: { reportDate?: string }) {
    return request<any, OverviewMetrics>({
      url: `${SUPPLY_CHAIN_BASE_URL}/overview`,
      method: "get",
      params,
    });
  },

  /**
   * 获取库存分析数据
   */
  getInventoryAnalysis(params?: { reportDate?: string }) {
    return request<any, InventoryAnalysis>({
      url: `${SUPPLY_CHAIN_BASE_URL}/inventory-analysis`,
      method: "get",
      params,
    });
  },

  /**
   * 获取周转分析数据
   */
  getTurnoverAnalysis(params?: DateRangeQuery) {
    return request<any, TurnoverAnalysis>({
      url: `${SUPPLY_CHAIN_BASE_URL}/turnover-analysis`,
      method: "get",
      params,
    });
  },

  /**
   * 获取目标达成数据
   */
  getTargetAchievement(params?: { reportDate?: string }) {
    return request<any, TargetAchievement>({
      url: `${SUPPLY_CHAIN_BASE_URL}/target-achievement`,
      method: "get",
      params,
    });
  },

  /**
   * 获取店铺表现排行
   */
  getStorePerformance(params?: StorePerformanceQuery) {
    return request<any, StorePerformance[]>({
      url: `${SUPPLY_CHAIN_BASE_URL}/store-performance`,
      method: "get",
      params,
    });
  },

  /**
   * 获取库存预警信息
   */
  getInventoryAlerts(params?: InventoryAlertQuery) {
    return request<any, InventoryAlert[]>({
      url: `${SUPPLY_CHAIN_BASE_URL}/inventory-alerts`,
      method: "get",
      params,
    });
  },

  /**
   * 获取趋势数据
   */
  getTrendData(params?: TrendQuery) {
    return request<any, TrendData>({
      url: `${SUPPLY_CHAIN_BASE_URL}/trend`,
      method: "get",
      params,
    });
  },

  /**
   * 刷新供应链数据
   */
  refreshData() {
    return request<any, string>({
      url: `${SUPPLY_CHAIN_BASE_URL}/refresh`,
      method: "post",
    });
  },
};

export default supplyChainApi; 